home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue60 / Clinic / LogoMain.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-05-31  |  4.5 KB  |  167 lines

  1. unit LogoMain;
  2.  
  3. interface
  4.  
  5. uses Windows, Classes, Graphics, Forms, Controls, Menus,
  6.   Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls;
  7.  
  8. type
  9.   TLogoAppForm = class(TForm)
  10.     MainMenu: TMainMenu;
  11.     FileMenu: TMenuItem;
  12.     FileNewItem: TMenuItem;
  13.     FileOpenItem: TMenuItem;
  14.     FileSaveItem: TMenuItem;
  15.     FileSendItem: TMenuItem;
  16.     FileExitItem: TMenuItem;
  17.     OpenDialog: TOpenDialog;
  18.     SaveDialog: TSaveDialog;
  19.     Help1: TMenuItem;
  20.     AboutItem: TMenuItem;
  21.     SpeedPanel: TPanel;
  22.     OpenBtn: TSpeedButton;
  23.     SaveBtn: TSpeedButton;
  24.     ExitBtn: TSpeedButton;
  25.     StatusBar: TStatusBar;
  26.     RichEdit1: TRichEdit;
  27.     SendBtn: TSpeedButton;
  28.     procedure FormCreate(Sender: TObject);
  29.     procedure FileExit(Sender: TObject);
  30.     procedure FileNew(Sender: TObject);
  31.     procedure FileOpen(Sender: TObject);
  32.     procedure FileSave(Sender: TObject);
  33.     procedure FileSaveAs(Sender: TObject);
  34.     procedure FileSend(Sender: TObject);
  35.     procedure About(Sender: TObject);
  36.     procedure ShowHint(Sender: TObject);
  37.   private
  38.     FFileName: String;
  39.   public
  40.     { Public declarations }
  41.   end;
  42.  
  43. var
  44.   LogoAppForm: TLogoAppForm;
  45.  
  46. implementation
  47.  
  48. uses SysUtils, Mapi, About, LogoStrs;
  49.  
  50. {$R *.DFM}
  51.  
  52. procedure TLogoAppForm.FormCreate(Sender: TObject);
  53. begin
  54.   Application.OnHint := ShowHint;
  55. end;
  56.  
  57. procedure TLogoAppForm.FileNew(Sender: TObject);
  58. begin
  59.   FFileName := LoadStr(sUntitled);
  60.   RichEdit1.Lines.Clear;
  61.   RichEdit1.Modified := False;
  62. end;
  63.  
  64. procedure TLogoAppForm.FileOpen(Sender: TObject);
  65. begin
  66.   if OpenDialog.Execute then
  67.   begin
  68.     RichEdit1.Lines.LoadFromFile(OpenDialog.FileName);
  69.     FFileName := OpenDialog.FileName;
  70.     RichEdit1.SetFocus;
  71.     RichEdit1.Modified := False;
  72.     RichEdit1.ReadOnly := ofReadOnly in OpenDialog.Options;
  73.   end;
  74. end;
  75.  
  76. procedure TLogoAppForm.FileSave(Sender: TObject);
  77. begin
  78.   if FFileName = LoadStr(sUntitled) then
  79.     FileSaveAs(Sender)
  80.   else
  81.   begin
  82.     RichEdit1.Lines.SaveToFile(FFileName);
  83.     RichEdit1.Modified := False;
  84.   end;
  85. end;
  86.  
  87. procedure TLogoAppForm.FileSaveAs(Sender: TObject);
  88. begin
  89.   if SaveDialog.Execute then
  90.   begin
  91.     if FileExists(SaveDialog.FileName) then
  92.       if MessageDlg(FmtLoadStr(sOverwrite, [SaveDialog.FileName]),
  93.         mtConfirmation, mbYesNoCancel, 0) <> idYes then Exit;
  94.     RichEdit1.Lines.SaveToFile(SaveDialog.FileName);
  95.     FFileName := SaveDialog.FileName;
  96.     RichEdit1.Modified := False;
  97.   end;
  98. end;
  99.  
  100. procedure SendMail(const Subject, MessageText, MailFromName, MailFromAddress,
  101.   MailToName, MailToAddress: String; const Attachments: array of String);
  102. var
  103.   MAPIError: DWord;
  104.   MapiMessage: TMapiMessage;
  105.   Originator, Recipient: TMapiRecipDesc;
  106.   Files, FilesTmp: PMapiFileDesc;
  107.   FilesCount: Integer;
  108. begin
  109.   FillChar(MapiMessage, Sizeof(TMapiMessage), 0);
  110.   MapiMessage.lpszSubject := PChar(Subject);
  111.   MapiMessage.lpszNoteText := PChar(MessageText);
  112.   FillChar(Originator, Sizeof(TMapiRecipDesc), 0);
  113.   Originator.lpszName := PChar(MailFromName);
  114.   Originator.lpszAddress := PChar(MailFromAddress);
  115.   MapiMessage.lpOriginator := @Originator;
  116.   MapiMessage.nRecipCount := 1;
  117.   FillChar(Recipient, Sizeof(TMapiRecipDesc), 0);
  118.   Recipient.ulRecipClass := MAPI_TO;
  119.   Recipient.lpszName := PChar(MailToName);
  120.   Recipient.lpszAddress := PChar(MailToAddress);
  121.   MapiMessage.lpRecips := @Recipient;
  122.   MapiMessage.nFileCount := High(Attachments) - Low(Attachments) + 1;
  123.   Files := AllocMem(SizeOf(TMapiFileDesc) * MapiMessage.nFileCount);
  124.   MapiMessage.lpFiles := Files;
  125.   FilesTmp := Files;
  126.   for FilesCount := Low(Attachments) to High(Attachments) do
  127.   begin
  128.     FilesTmp.nPosition := $FFFFFFFF;
  129.     FilesTmp.lpszPathName := PChar(Attachments[FilesCount]);
  130.     Inc(FilesTmp)
  131.   end;
  132.   try
  133.     MAPIError := MapiSendMail(0, Application.MainForm.Handle,
  134.       MapiMessage, MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
  135.     if MAPIError <> 0 then
  136.       MessageDlg(LoadStr(sSendError), mtError, [mbOK], 0)
  137.   finally
  138.     FreeMem(Files)
  139.   end
  140. end;
  141.  
  142. procedure TLogoAppForm.FileSend(Sender: TObject);
  143. begin
  144.   SendMail('Subject', 'Message text',
  145.     'The Delphi Clinic', 'clinic@blong.com',
  146.     'The Delphi Magazine', 'chrisf@itecuk.com',
  147.     ['c:\autoexec.bat'])
  148. end;
  149.  
  150. procedure TLogoAppForm.FileExit(Sender: TObject);
  151. begin
  152.   Close;
  153. end;
  154.  
  155. procedure TLogoAppForm.About(Sender: TObject);
  156. begin
  157.   AboutBox.ShowModal;
  158. end;
  159.  
  160. procedure TLogoAppForm.ShowHint(Sender: TObject);
  161. begin
  162.   StatusBar.SimpleText := Application.Hint;
  163. end;
  164.  
  165. end.
  166.  
  167.